package cn.tedu.charcount;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;


/**
 * 启动类
 * @author waqwb
 *
 */
public class CharCountDriver {
	public static void main(String[] args) throws Exception {
		//获取环境配置
		Configuration conf = new Configuration();
		//向yarn申请一个job任务
		Job job = Job.getInstance();
		//设置入口类
		job.setJarByClass(CharCountDriver.class);
		//设置Mapper类
		job.setMapperClass(CharCountMapper.class);
		//设置Reducer类
		job.setReducerClass(CharCountReducer.class);

		//设置Mapper的输出类型
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(LongWritable.class);
		//设置Recuder的输出类型
		job.setOutputKeyClass(Text.class);//字符
		job.setOutputValueClass(LongWritable.class);//次数
		//设置文件输入路径，在hdfs上
		FileInputFormat.addInputPath(job,
				new Path("hdfs://hadoop01:9000/txt/characters.txt"));
		//设置输出路径，要求输出路径必须不存在
		FileOutputFormat.setOutputPath(job,
				new Path("hdfs://hadoop01:9000/result/char_count"));
		//提交任务
		job.waitForCompletion(true);
	}
}
